#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPushButton>
#include <QLineEdit>
#include <QSpinBox>
#include <QGroupBox>
#include <QLabel>
#include "jsonprocessor.h"
#include "txtprocessor.h"
#include "srtprocessor.h"
#include "txttojsonprocessor.h"
#include "jsontosrtprocessor.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    // UI组件
    QLineEdit* jsonFilePathEdit;
    QPushButton* selectJsonFileBtn;
    QPushButton* processJsonBtn;
    QLineEdit* jsonKeywordsEdit;
    
    QLineEdit* txtFilePathEdit;
    QPushButton* selectTxtFileBtn;
    QPushButton* processTxtBtn;
    QLineEdit* txtKeywordsEdit;
    
    QLineEdit* untranslatedSrtPathEdit;
    QLineEdit* translatedSrtPathEdit;
    QPushButton* selectUntranslatedSrtBtn;
    QPushButton* selectTranslatedSrtBtn;
    QPushButton* processSrtBtn;
    
    QLineEdit* txtToJsonInputEdit;
    QPushButton* selectTxtToJsonInputBtn;
    QPushButton* processTxtToJsonBtn;
    
    QLineEdit* jsonToSrtInputEdit;
    QPushButton* selectJsonToSrtInputBtn;
    QPushButton* processJsonToSrtBtn;
    
    // 长度限制输入框
    QSpinBox* minLengthSpinBox;
    QSpinBox* maxLengthSpinBox;
    
    // 处理器
    JsonProcessor jsonProcessor;
    TxtProcessor txtProcessor;
    SrtProcessor srtProcessor;
    TxtToJsonProcessor txtToJsonProcessor;
    JsonToSrtProcessor jsonToSrtProcessor;

    // 关键词相关
    const QString jsonKeywordsFileName = "json_keywords.txt";
    const QString txtKeywordsFileName = "txt_keywords.txt";
    bool saveKeywords(const QStringList& keywords, const QString& fileName);
    QStringList loadKeywords(const QString& fileName);

    // 私有方法
    void setupUi();
    void selectJsonFile();
    void processJson();
    void selectTxtFile();
    void processTxt();
    void selectUntranslatedSrt();
    void selectTranslatedSrt();
    void processSrt();
    void selectTxtToJsonInput();
    void processTxtToJson();
    void selectJsonToSrtInput();
    void processJsonToSrt();
    
    QStringList getKeywordsList(const QString& keywords);
    void initializeKeywords();
};
#endif // MAINWINDOW_H
